package com.example.pixelyear.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.example.pixelyear.R
import com.example.pixelyear.utils.UIUtils
import com.example.pixelyear.utils.extension.setOnDoubleClickListener

/**
 * 情绪Adapter
 */
class MoodAdapter(val context: Context) : BaseAdapter<String>() {
    var lastChoose = 0
    var nowChoose = 0

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        return BaseViewHolder(LayoutInflater.from(context).inflate(R.layout.textview, parent, false))
    }

    override fun onBindView(itemView: View, bean: String, position: Int) {
        val textView = itemView as TextView
        textView.text = bean
        if (nowChoose == position) {
            itemView.setTextColor(UIUtils.getColor(R.color.blue_2595e4))
        } else {
            itemView.setTextColor(UIUtils.getColor(R.color.color_333333))
        }

        textView.setOnClickListener {
            onItemClick?.click(bean, position)
            nowChoose = position
            notifyItemChanged(nowChoose)
            if (lastChoose != -1)
                notifyItemChanged(lastChoose)
            lastChoose = position
        }
    }

    fun updatePosition(index: Int, bean: String) {
        onItemClick?.click(bean, index)
        nowChoose = index
        notifyItemChanged(nowChoose)
        if (lastChoose != -1)
            notifyItemChanged(lastChoose)
        lastChoose = index
    }

}
